var param={};
var exportparam={}; 
//从业务设置中获取是否启用序列号
var myPage;
// 列表----重新加载数据
  
// 列表配置
function table_init() {
	  
	var page_colmodel=new Array(); 
	page_colmodel.push({
		display : '序号',
		name : 'xh',
		width : '30',
		isNo : true 
	}); 
	page_colmodel.push({
		display : '编号',
		name : 'idcode', 
		isConfigurable : true, 
		isHide : false,
		align : 'left',
		width : '60'
	});
	page_colmodel.push({
		display: '车型',
		name : 'cx',
		isConfigurable : true,
		isHide : false,
		align : 'left',
		width : '50'
	});
	page_colmodel.push({
		display: '目录或功能',
		name : 'leveltype',
		isConfigurable : true,
		isHide : false,
		align : 'left',
		width : '70'
	});
	page_colmodel.push({
		display : '是否录音',
		name : 'isvoice', 
		isConfigurable : true,
		isHide : false, 
		replaceHtmlFunction:'replaceHtmlvoice',
		width : '60'
	});
	 
	page_colmodel.push({
		display: '是否拍照',
		name : 'isphoto',
		isConfigurable : true,
		isHide : false,
		replaceHtmlFunction:'replaceHtmlphoto',
		width : '60'
	});
	page_colmodel.push({
		display: '是否录像',
		name : 'isvidio',
		isConfigurable : true,
		isHide : false,
		replaceHtmlFunction:'replaceHtmlvdio',
		width : '60' 
	});
	page_colmodel.push({
		display: '是否NFC',
		name : 'isnfc',
		isConfigurable : true,
		isHide : false, 
		replaceHtmlFunction:'replaceHtmlnfc',
		width : '60'
	});
	page_colmodel.push({
		display: 'NFC部位',
		name : 'nfcposition',
		isConfigurable : false,
		isHide : false, 
		width : '90'
	}); 
	page_colmodel.push({
		display: '是否统计',
		name : 'istj',
		isConfigurable : false,
		isHide : false, 
		replaceHtmlFunction:'replaceHtmltj',
		width : '60'
	});
	page_colmodel.push({
		display: '一级扣分分值',
		name : 'timemack',
		isConfigurable : true,
		replaceHtmlFunction:'replaceHtmlyj',
		isHide : false,  
		width : '100'
	});
	page_colmodel.push({
		display: '扣分时间区间',
		name : 'count',
		isConfigurable : true,
		isHide : false,  
		width : '100'
	});
	page_colmodel.push({
		display: '扣分时间分值',
		name : 'countmack',
		isConfigurable : true,
		isHide : false,  
		width : '100'
	});
	page_colmodel.push({
		display : '操作',
		name : '',
		width : '160',
		isRemark : true,
		remarkContent : '如果删除父级，则会删除所有子级',
		sortable : false,
		isButton : true
	});
	var page_buttons = [ {
		name : '详细',
		bclass : 'operate details',
		onpress : 'detailRecord'
	}, {
		name : '编辑',
		bclass : 'operate edit',
		onpress : 'editRecord'
	}, {
		name : '删除',
		bclass : 'operate del',
		onpress : 'deleteRecord'
	} 
	];
	
	var page = {
		id : "gx",		
		keycol:"idcode",
		url : "gxgljson_loadtablelist.action",
		dataType : 'json',
		colModel : page_colmodel,
		buttons : page_buttons,
		sortname : "idcode",
		sortorder : "asc",
		usepager : false,
		useRp : true,
		rp : 20,
		showTableToggleBtn : false,
		width : 'auto',
		height : 'auto',
		isTree:true,
		setPageParams : 'table_getPageParams()',
		detailRowNumber : 5
	};
	myPage = page;
	$("#resultList").flexigrid(page);
}
function replaceHtmlyj(i) {
	var data = getData(i); 
	if (data.idcode.length==3)
	{
		return data.timemack;
	}else{
		return "<span></span>";
	}
	 
}
function replaceHtmltj(i) {
	var data = getData(i); 
	if (data.leveltype=="功能")
	{
		if(data.istj ==1){
			return "是";
		}else{
			return "否";
		}
	}else{
		return "<span></span>";
	}
	 
}
function replaceHtmlnfc(i) {
	var data = getData(i);
	if (data.leveltype=="功能")
	{
		if(data.isnfc ==1){
			return "卡";
		}else{
			return "<span></span>";
		}
	}else{
		return data.isnfc ==null ? 0 :data.isnfc;
	} 
}
function replaceHtmlvoice(i) {
	var data = getData(i);
	if (data.leveltype=="功能")
	{
		if(data.isvoice ==1){
			return "音";
		}else{
			return "<span></span>";
		}
	}else{
		return data.isvoice ==null ? 0 :data.isvoice;
	}  
}
function replaceHtmlphoto(i) {
	var data = getData(i);
	if (data.leveltype=="功能")
	{
		if(data.isphoto ==1){
			return "照";
		}else{
			return "<span></span>";
		}
	}else{
		return data.isphoto ==null ? 0 :data.isphoto;
	}  
	 
}
function replaceHtmlvdio(i) {
	var data = getData(i);
	if (data.leveltype=="功能")
	{
		if(data.isphoto ==1){
			return "像";
		}else{
			return "<span></span>";
		}
	}else{
		return data.isphoto ==null ? 0 :data.isphoto;
	}   
}
// 编辑商品
function editRecord(i) { 
	var data = getData(i);
	var tabname = "工序编辑";
	var text = "工序编辑";
	var href = top.urlpath + "/gxgl_toupdate.action?idcode=" + data.idcode; 
	top.maincontab.opentabs(href,text,"0",tabname); 
}
// 删除商品
function getchildsrow(arryrows,row) {
	arryrows.push(row);
	if(row.trChildrents && row.trChildrents.length >0)
	{
		$.each(row.trChildrents, function(i, child) {
			getchildsrow(arryrows,child);
		} );
	} 
	return arryrows;
}

function deleteRecord(i) {
	 
	var data = getData(i);
	var rows =new Array();
	rows = getchildsrow(rows,data);
	var idcodes="";
	$.each(rows, function(i, child) {
		idcodes +=child.idcode +"#";
	} );
	if(idcodes.length > 0)
	{
		idcodes=idcodes.substring(0,idcodes.length-1);
	}
	layer.confirm("确认删除工序"+data.sys_name+"吗？", {
		  btn: ['确定','取消'] //按钮
		}, function(){
			var param = {};
			param["idcode"] = idcodes; 
			$.post(top.urlpath + "/gxgljson_deletetablelist.action", param, function(result, resultState) {
				if (result.state == "0") {
					top.showSuccessMsg("删除成功");  
					layer.closeAll(); 
					$("#resultList").flexReload(myPage);
					$("#selectAllCheckbox").removeAttr("checked");
				}else
				{
					top.showErrorMsg("删除失败");  
					cancelSelect();
				} 
			});
		}); 
} 

function cancelSelect()
{
	 $('input[type="checkbox"][name="fcheckbox"]:checked').each(
	     function() {
	    	 $(this).attr("checked", false); 
         }
     );
}

// 详细
function detailRecord(i)
{ 
	var data = getData(i);
	var tabname = "工序详细";
	var text = "工序详细";
	var href = top.urlpath + "/gxgl_todetail.action?idcode=" + data.idcode; 
	top.maincontab.opentabs(href,text,"0",tabname); 
}
   
//列表----获取查询参数
function table_getPageParams() {
	//高级搜索
	var params = [ 
	{
		name : 'keyword',
		value : $("#keyword").val()
	},
	{
		name : 'querytype',
		value : $("#querytype").val()
	},
	{
		name : 'idcode',
		value : $("#search_idcode").val()
	},
	{
		name : 'sys_name',
		value : $("#search_sys_name").val()
	},
	{
		name : 'classid',
		value : $("#classid").val()
	}];
	exportparam=params;
	return params;
}